package com.wgts.wgts.mvp.view.activity.awardmore;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wgts.wgts.R;
import com.wgts.wgts.control.recycleview.BaseLoadMoreAdapter;

import com.wgts.wgts.netmodle.resp.AwardMoreListEntity;
import com.wgts.wgts.tools.AppInfor;
import com.wgts.wgts.tools.MoHuGlide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/*
 *
 *
 *   data:2018/10/919:44
 *
 */public class AwardRecycleAdapter extends RecyclerView.Adapter<AwardRecycleAdapter.ViewHold> {
    private Context context;
    private List<AwardMoreListEntity> list;

    private OnClickListener onClickListener;

    public AwardRecycleAdapter(Context context, List<AwardMoreListEntity> list) {
        this.context = context;
        this.list = list;
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    @NonNull
    @Override
    public ViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ViewHold(LayoutInflater.from(context).inflate(R.layout.award_goods_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHold viewHold, final int i) {
        MoHuGlide.getInstance().glideImg(context, list.get(i).productSmallImage, viewHold.shopImage);
        viewHold.shopName.setText(list.get(i).productName);
        viewHold.shopPrice.setText("￥" + list.get(i).productPrice);
        if (AppInfor.getInstance().getUserState() < 2 || AppInfor.getInstance().getRefreshToken().equals("")){
            viewHold.joinButtonText.setText("发起活动");
        }else {
            switch (list.get(i).status){
                //未开始
                case "PENDING":
                    viewHold.joinButtonLy.setBackgroundResource(R.drawable.award_no_use);
                    viewHold.joinButtonText.setText("暂不可用");
                    break;
                //可发起
                case "INITIATE":
                    viewHold.joinButtonLy.setBackgroundResource(R.drawable.award_more_join_border);
                    viewHold.joinButtonText.setText("发起活动");
                    break;
                //进行中
                case "ACTIVE":
                    viewHold.joinButtonLy.setBackgroundResource(R.drawable.award_more_join_border);
                    viewHold.joinButtonText.setText("继续邀请");
                    break;
                //未开奖
                case "UNOPENED":
                    viewHold.joinButtonLy.setBackgroundResource(R.drawable.award_more_join_border);
                    viewHold.joinButtonText.setText("立即开奖");
                    break;
            }
        }

        viewHold.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                if (AppInfor.getInstance().getUserState() < 2){
//                    //升级店主
//                }else {
//                    switch (list.get(i).status){
//                        //未开始
//                        case "PENDING":
//
//                            break;
//                        //可发起
//                        case "INITIATE":
//
//                            break;
//                        //进行中
//                        case "ACTIVE":
//
//                            break;
//                        //未开奖
//                        case "UNOPENED":
//
//                            break;
//                    }
//                }

                if(onClickListener != null){
                    onClickListener.onClick(v, i);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class ViewHold extends RecyclerView.ViewHolder {
        @BindView(R.id.shop_image)
        ImageView shopImage;
        @BindView(R.id.shop_name)
        TextView shopName;
        @BindView(R.id.shop_price)
        TextView shopPrice;
        @BindView(R.id.join_peoples)
        TextView joinPeoples;
        @BindView(R.id.join_type)
        TextView joinType;
        @BindView(R.id.join_button_text)
        TextView joinButtonText;
        @BindView(R.id.join_button_ly)
        RelativeLayout joinButtonLy;
        private View itemView;
        public ViewHold(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.itemView = itemView;
        }
    }

    public interface OnClickListener{
        void onClick(View view, int i);
    }
}
